import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'shop_controller.dart';
import 'shop_model.dart';

class ShopItemWidget extends StatefulWidget {
  final GoodsModel element;
  ShopItemWidget(this.element);

  @override
  _ShopItemWidgetState createState() => _ShopItemWidgetState();
}

class _ShopItemWidgetState extends State<ShopItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(10),
      margin: EdgeInsets.only(top: 10),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 商品照片
          Image.asset("assets/images/app_icon.png", width: 100, height: 80),
          SizedBox(width: 20),
          // 商品的介绍
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("${widget.element.title}"),
                Text("${widget.element.subTitle}"),
                Row(
                  children: [
                    Expanded(child: Text("${widget.element.price}")),
                    TextButton(
                      onPressed: () {
                        widget.element.isCard = !widget.element.isCard;
                        setState(() {});
                        Get.find<ShopController>().addCard(widget.element);
                      },
                      child: Text(widget.element.isCard ? '移除购物车' : '加入购物车'),
                    )
                  ],
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
